****************************************************************************************************************************************
* Reproduction file for "The globalisation divide in the public mind: Belief systems on globalisation and their electoral consequences *
****************************************************************************************************************************************

* This do file reproduces all (Stata based) results for the GLES campaing panel reported in the ARTICLE
* Run GLES_01_clean_data.do before


*** Table 1: Stability of globalization attitudes and norms to vote 
	use "DATA_stata.dta", clear
	recode globadiff83 globadiff98 globadiff93 globadiff983 vnormadiff85 vnormadiff98 vnormadiff95 vnormadiff985 (3 4 5 6 7 8 = 3) // code "3 scale points or more" category

	*ssc install tab_chi // tabm command is part of the tab_chi ado package
	tabm globadiff83 globadiff98 globadiff93 globadiff983 vnormadiff85 vnormadiff98 vnormadiff95 vnormadiff985, column nof transpose 

	
*** Table 2: ESEM loadings of the globalisation and new and old policy issue items -> see Mplus files


*** Table 3: Correlations of globalisation and new and old issue dimensions -> see Mplus files


*** Figure 2: Effects of attitudes towards globalisation and globalisation issues on vote choice
	use "DATA_stata.dta", clear

	*** Listwise deletion for all models; keep observations constant
	global controls "ib8.pi c.age_indec##c.age_indec i.female i.educat i.incomecat i.east ecsit_ego1 ecsit_soc1"
		quietly reg vote glob_i ecoopen_i europe_i immi_i redis_i civlib_i cultlib1x $controls 
		keep if e(sample)

	* Model 1: Globalisation attitude only, without attitudes towards globalisation issues
	mlogit vote glob_i redis_i civlib_i cultlib1x $controls
	estimate store m1
	
			forvalues p = 1/8 {
			estimate restore m1
			margins, dydx(glob_i redis_i civlib_i cultlib1x) predict(outcome(`p')) post
			estimate store marg_A`p'
			}
			
			coefplot marg_A1 || marg_A2 || marg_A3 || marg_A4 || marg_A5 || marg_A6 || marg_A7 || marg_A8, scheme(plotplainblind) ///
				coeflabels(glob_i = "Globalisation" redis_i = "Redistribution" civlib_i = "Civil liberties" cultlib1x = "Cultural liberalism") ///
				order(glob_i ecoopen_i europe_i immi_i) ///
				xline(0, lcolor(gs0) lwidth(thin)) xscale(range(-.4 .2)) xlabel(-.4  (.2) .2) bylabels("CDU/CSU" "FDP" "SPD" "Greens" "Left" "AfD" "Other party" "Did not vote") ///
				byopts(row(2) title("Model 1: Globalisation attitude only, without attitudes towards globalisation issues"))  ///
				fysize(40) ///
				name(AMEs_vote_onlyglob, replace) 		
	
	* Model 2: Full model, including attitudes towards globalisation issues
	mlogit vote glob_i ecoopen_i europe_i immi_i redis_i civlib_i cultlib1x $controls
	estimate store m2
	
		forvalues p = 1/8 {
		estimate restore m2
		margins, dydx(glob_i ecoopen_i europe_i immi_i redis_i civlib_i cultlib1x) predict(outcome(`p')) post
		estimate store marg_C`p'
		}
				
		coefplot marg_C1 || marg_C2 || marg_C3 || marg_C4 || marg_C5 || marg_C6 || marg_C7 || marg_C8, scheme(plotplainblind) ///
			coeflabels(glob_i ="Globalisation" europe_i ="European integration" immi_i = "Immigration" ecoopen_i = "Economic openness" redis_i = "Redistribution" civlib_i = "Civil liberties" cultlib1x = "Cultural liberalism") ///
			order(glob_i ecoopen_i europe_i immi_i) ///
			xline(0, lcolor(gs0) lwidth(thin)) xscale(range(-.4 .2)) xlabel(-.4  (.2) .2) bylabels("CDU/CSU" "FDP" "SPD" "Greens" "Left" "AfD" "Other party" "Did not vote") ///
			byopts(row(2)title("Model 2: Full model, including attitudes towards globalisation issues")) ///
			fysize(50) ///
			name(AMEs_vote_both, replace) 	
	
	* Combine graphs to Figure 2	
	graph combine AMEs_vote_onlyglob AMEs_vote_both, rows(2) xsize(6.5) iscale(*1.5) imargin(vsmall)  name(Figure3, replace) 
	graph export Figure2.pdf, replace


*** Figure 3: Effects of globalisation attitude on vote choice
		* Computed predicted probabilities
		forvalues p = 1/8 {
		estimate restore m2
			margins, at(glob_i=(0 (0.1) 1)) predict(outcome(`p')) post
			if `p'==1  local title="CDU/CSU" 		
			if `p'==2  local title="FDP" 
			if `p'==3  local title="SPD" 
			if `p'==4  local title="Greens" 
			if `p'==5  local title="Left" 
			if `p'==6  local title="AfD" 
			if `p'==7  local title="Other party" 
			if `p'==8  local title="Did not vote"
			marginsplot, ///
					legend(off) ///
					xtitle("Globalisation attitude") ytitle(" ") ///
					ylabel(0 (.1) 0.3) xlabel(0 (.2) 1) ///
					addplot(hist glob_i if e(sample) & vote==`p', percent bin(11) yaxis(2) yscale(alt range(0 220) axis(2)) ylabel(none, axis(2)) ytitle(" ", axis(2)) ylabel(0 (.1) 0.3) xlabel(0 (.2) 1))  ///
					ylabel(0 (.1) 0.3) xlabel(0 (.2) 1) ///
					title("`title'", size(medlarge)) scheme(plotplainblind) ///
					name(pred_C`p', replace) 				
			}
		
		* Combine graphs to Figure 3	
		graph combine pred_C1 pred_C2 pred_C3 pred_C4 pred_C5 pred_C6 pred_C7 pred_C8, ycommon imargin(vsmall) iscale(*1.2) rows(2)
		graph export Figure3.pdf, replace

		
*** Text: Predicted vote probabilities for globalisation supporters and opponents
		estimate restore m2
		* CDU/CSU
		margins, at(glob_i=(0 1)) predict(outcome(1))
		* AfD
		margins, at(glob_i=(0 1)) predict(outcome(6))
		* Left Party
		margins, at(glob_i=(0 1)) predict(outcome(5))
